/**
 * Created by Administrator on 2017/7/12.
 */
define(['jquery', "vue"], function ($, Vue) {
    mui.init();
    var buy = [];

    var vue = new Vue({
        el: '#order_page',
        data: {},
        methods: {
            add_order: function () {
                var data = {
                    cart_ids: cart_ids
                };
                var check_address_radio = document.getElementById("order_page").querySelector('input[type="radio"][name="address"]:checked');
                var address_id = check_address_radio.value;
                if (address_id === "") {
                    window.location.href = address_url;
                }
                if (address_id > 0) {
                   // $("#other_address").hide();
                    data.address_id = address_id;
                }
                else {
                   // $("#other_address").show();
                    var o_address = $("#o_address").val();
                    var o_mobile = $("#o_mobile").val();
                    if (o_address === "" || o_address === null) {
                        mui.alert("请填写收货地址");
                        return;
                    }
                    // if (o_mobile === "" || o_mobile === null) {
                    //     mui.alert("请填写联系电话");
                    //     return;
                    // }
                    data.o_address = o_address;
                    data.o_province = $("#o_province").val();
                    data.o_city = $("#o_city").val();
                    data.o_district = $("#o_district").val();
                    data.o_lng = $("#o_lng").val();
                    data.o_lat = $("#o_lat").val();
                    data.o_zoom = $("#o_zoom").val();
                    data.o_name = $("#o_name").val();
                    data.o_mobile = o_mobile;
                }

                data.remark = $("#remark").val();
                mui.confirm('配送费5元起', '系统提示', ['取消', '确定'], function (e) {
                    if (e.index === 1) {
                        $.post(add_order_url, data, function (res) {
                                if (res.code === 1) {
                                    // mui.alert("每单配送费为配送员送达后收取（5元起）", '系统提示', function () {
                                    //     window.location.href = pay_url + "/order_id/" + res.data.order_id;
                                    // }, 'div');

                                    window.location.href = pay_url + "?order_id=" + res.data.order_id;

                                } else {
                                    mui.alert(res.msg);
                                }
                            }
                        )
                    }
                })
            },
            other_check:function () {
                var check = event.currentTarget;
                console.log(check.checked);
                if (check.checked) {
                    $("#other_address").show();
                }else {
                    $("#other_address").hide();
                }
            },
            default_check:function () {
                var check = event.currentTarget;
                if (check.checked) {
                    $("#other_address").hide();
                }else {
                    $("#other_address").show();
                }
            }
        }
    });
    document.getElementById("set_address").addEventListener("tap", function (e) {
        if (e.target != document.querySelector("#set_address input")) {
            window.location.href = address_url + "?back_url=" + c_url;
        }
    })
});